home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / include / tfm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-06  |  11.0 KB  |  300 lines

  1. /* tfm.h: read and write TeX font metric files.  See Metafont: The
  2.    Program, by Don Knuth, (Volume D of Computers & Typesetting), chapter 45,
  3.    among other places, for the precise definition of this format.
  4.  
  5. Copyright (C) 1992 Free Software Foundation, Inc.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #ifndef TFM_FONT_LIBRARY_H
  22. #define TFM_FONT_LIBRARY_H
  23.  
  24. #include "fix-num.h"
  25. #include "list.h"
  26. #include "types.h"
  27.  
  28.  
  29. /* Only one input file may be open at a time.  You therefore do not give a
  30.    file as a parameter to the routines.  */
  31. extern boolean tfm_open_input_file (string filename);
  32. extern void tfm_close_input_file (void);
  33.  
  34. /* The name of the currently open input file, or NULL if none.  */
  35. extern string tfm_input_filename (void);
  36.  
  37.  
  38. /* We output a property list file, since it is so much easier to deal
  39.    with than the binary tfm format.  The program PLtoTF, which is part
  40.    of the standard TeX distribution, converts from the one to the other.  */
  41. extern boolean tfm_open_pl_output_file (string filename);
  42. extern void tfm_close_pl_output_file (void);
  43.  
  44. /* This uses the PL filename to `tfm_open_pl_output_file' and invokes
  45.    PLtoTF to output a TFM file with the same root and extension `.tfm',
  46.    unless TFM_NAME is non-null, in which it is used.  You should not
  47.    call `tfm_close_pl_output_file' before calling this.  This flushes
  48.    all the data written before converting.  */
  49. extern void tfm_convert_pl (string tfm_name, boolean verbose);
  50.  
  51.  
  52. /* The restriction to 256 characters in a TFM file is part of the file
  53.    format, so this number should only be changed in the (very unlikely)
  54.    event that the file format changes.  */
  55. #define TFM_SIZE 256
  56.  
  57. /* Fontwide information.  All real values are in printer's points:
  58.    72.27 points = 1 inch.  */
  59.  
  60. /* TFM_MIN_DESIGNSIZE <= designsize < TFM_MAX_DESIGNSIZE.  */
  61. #define TFM_MIN_DESIGNSIZE 1.0
  62. #define TFM_MAX_DESIGNSIZE 2048
  63.  
  64. /* Check that a design size's value is in range.  */
  65. #define TFM_CHECK_DESIGN_SIZE(ds)                    \
  66. if ((ds) < TFM_MIN_DESIGNSIZE || TFM_MAX_DESIGNSIZE <= (ds))        \
  67.   FATAL3 ("Design size %.2f is outside range %.1f to %d",        \
  68.           ds, TFM_MIN_DESIGNSIZE, TFM_MAX_DESIGNSIZE);
  69.  
  70. /* The maximum number of global font parameters we allow.  */
  71. #define TFM_MAX_FONTDIMENS 30
  72.  
  73. /* The maximum length of a codingscheme string.  */
  74. #define TFM_MAX_CODINGSCHEME_LENGTH 39
  75.  
  76.  
  77. typedef struct
  78. {
  79.   charcode_type first_charcode, last_charcode;
  80.   four_bytes checksum;
  81.   real design_size;
  82.   string coding_scheme;
  83.   unsigned parameter_count;
  84.   real parameters[TFM_MAX_FONTDIMENS];
  85. } tfm_global_info_type;
  86.  
  87. /* The checksum.  */
  88. #define TFM_CHECKSUM(info) ((info).checksum)
  89.  
  90. /* The design size of the font.  */
  91. #define TFM_DESIGN_SIZE(info) ((info).design_size)
  92.  
  93. /* The coding scheme.  */
  94. #define TFM_CODING_SCHEME(info) ((info).coding_scheme)
  95.  
  96. /* How many parameters are actually being used.  */
  97. #define TFM_FONTDIMEN_COUNT(info) ((info).parameter_count)
  98.  
  99. /* The NUMBERth parameter of the `tfm_global_info_type' variable INFO,
  100.    in points.  Since font parameters are numbered starting at 1, and the
  101.    C array starts at 0, we subtract 1 from NUMBER.  */
  102. #define TFM_FONTDIMEN(info, number) ((info).parameters[(number) - 1])
  103.  
  104. /* Like TFM_FONTDIMEN, but if NUMBER is out of range return RET.  */
  105. #define TFM_SAFE_FONTDIMEN(info, number, ret)                \
  106.   ((number) - 1 < TFM_FONTDIMEN_COUNT (info)                 \
  107.    ? TFM_FONTDIMEN (info, number) : (ret))
  108.  
  109. /* Define symbolic names for the numbers of the parameters we
  110.    recognize.  Some numbers have more than one name.  */
  111. #define TFM_SLANT_PARAMETER 1
  112. #define TFM_SPACE_PARAMETER 2
  113. #define TFM_STRETCH_PARAMETER 3
  114. #define TFM_SHRINK_PARAMETER 4
  115. #define TFM_XHEIGHT_PARAMETER 5
  116. #define TFM_QUAD_PARAMETER 6
  117. #define TFM_EXTRASPACE_PARAMETER 7
  118. #define TFM_NUM1_PARAMETER 8
  119. #define TFM_NUM2_PARAMETER 9
  120. #define TFM_NUM3_PARAMETER 10
  121. #define TFM_DENOM1_PARAMETER 11
  122. #define TFM_DENOM2_PARAMETER 12
  123. #define TFM_SUP1_PARAMETER 13
  124. #define TFM_SUP2_PARAMETER 14
  125. #define TFM_SUP3_PARAMETER 15
  126. #define TFM_SUB1_PARAMETER 16
  127. #define TFM_SUB2_PARAMETER 17
  128. #define TFM_SUPDROP_PARAMETER 18
  129. #define TFM_SUBDROP_PARAMETER 19
  130. #define TFM_DELIM1_PARAMETER 20
  131. #define TFM_DELIM2_PARAMETER 21
  132. #define TFM_AXISHEIGHT_PARAMETER 22
  133. #define TFM_DEFAULTRULETHICKNESS_PARAMETER 8
  134. #define TFM_BIGOPSPACING1_PARAMETER 9
  135. #define TFM_BIGOPSPACING2_PARAMETER 10
  136. #define TFM_BIGOPSPACING3_PARAMETER 11
  137. #define TFM_BIGOPSPACING4_PARAMETER 12
  138. #define TFM_BIGOPSPACING5_PARAMETER 13
  139.  
  140. /* These are not in any of the standard TeX fonts, but the information
  141.    is useful nevertheless.  */
  142. #define TFM_LEADINGHEIGHT_PARAMETER 23
  143. #define TFM_LEADINGDEPTH_PARAMETER 24
  144. #define TFM_FONTSIZE_PARAMETER 25
  145. #define TFM_VERSION_PARAMETER 26
  146.  
  147. /* Return the global info from the current input font.  */
  148. extern tfm_global_info_type tfm_get_global_info (void);
  149.  
  150. /* We could have more routines here, one for each global quantity. 
  151.    These call `tfm_get_global_info' for you, so that if all you are
  152.    interested in is, say, the interword space, you can get only that.  */
  153. extern unsigned tfm_get_checksum (void);
  154. extern double tfm_get_design_size (void);
  155. extern string tfm_get_coding_scheme (void);
  156. extern double tfm_get_interword_space (void);
  157. extern double tfm_get_x_height (void);
  158.  
  159.  
  160. /* Return an initialized structure.  This doesn't read any files.  */
  161. extern tfm_global_info_type tfm_init_global_info (void);
  162.  
  163.  
  164. /* The `first_charcode', `last_charcode', and `parameter_count'
  165.    members of this structure are computed automatically.  The rest of
  166.    the structure is output to the PL file.  */
  167. extern void tfm_put_global_info (tfm_global_info_type);
  168.  
  169.  
  170. /* Set the header in TFM_INFO according to the string S, which
  171.    should look like: <header-item>:<value>,<header-item>:<value>,...,
  172.    where each <header-item> is <header-item> can be one of the strings
  173.    `checksum', `designsize' or `codingscheme', with casefolding.  `checksum'
  174.    requires <four-bytes>, `designsize' a <real>, with TFM_MIN_DESIGNSIZE
  175.    <= <real> <= TFM_MAX_DESIGNSIZE, and `codingscheme' a <string> of
  176.    length not greater than TFM_MAX_CODINGSCHEME_LENGTH and containing no
  177.    parentheses or commas.  */
  178. extern void tfm_set_header (string s, tfm_global_info_type *tfm_info);
  179.  
  180. /* Set the design (and font size) of TFM_INFO to DESIGN_SIZE, if they're
  181.    not set already.  */
  182. extern void tfm_set_design_size (real design_size,
  183.                                  tfm_global_info_type *tfm_info);
  184.  
  185. /* Set values in INFO according to the specification in S, which should
  186.    look like `<fontdimen>:<real>,<fontdimen>:<real>,...', where each
  187.    <fontdimen> is either a number between 1 and TFM_MAX_FONTDIMENS
  188.    or one of the standard names.  */
  189. extern void tfm_set_fontdimens (string s, tfm_global_info_type *info);
  190.  
  191. /* Return the fontdimen number of S if we recognize it as the name of a
  192.    fontdimen, else zero.  */
  193. extern unsigned tfm_fontdimen_number (string s);
  194.  
  195. /* Return the fontdimen name corresponding to the number N if there is
  196.    one, else NULL.  The first fontdimen is numbered 1.  If there is more
  197.    than one name for N, it's arbitrary which is returned.  */
  198. extern string tfm_fontdimen_name (unsigned n);
  199.  
  200. /* Set parameter P in INFO to V.  Set any intervening parameters
  201.    between the previous last parameter set in TFM_INFO and P to zero.  */
  202. extern void tfm_set_fontdimen (tfm_global_info_type *info, unsigned p, real v);
  203.             
  204. /* Set the `fontsize' fontdimen in TFM_INFO to the designsize, if the
  205.    latter is set.  */
  206. extern void tfm_set_fontsize (tfm_global_info_type *tfm_info);
  207.  
  208. /* We store the character dimensions we read as both approximate
  209.    floating point values, in printer's points, and as (unscaled by the
  210.    design_size) `fix_word' values.  On output, we look only at the
  211.    former.  */
  212.  
  213. typedef struct
  214. {
  215.   boolean exists;
  216.   charcode_type code;
  217.   real width, height, depth, italic_correction;
  218.   fix_word fix_width, fix_height, fix_depth, fix_italic_correction;
  219.   list_type kern;
  220.   list_type ligature;
  221. } tfm_char_type;
  222.  
  223. /* Says whether or not this character was in the TFM file.  */
  224. #define TFM_CHAR_EXISTS(tc) ((tc).exists)
  225.  
  226. /* The character code.  */
  227. #define TFM_CHARCODE(tc) ((tc).code)
  228.  
  229. /* The (possibly negative) dimensions, in points and fixes.  */
  230. #define TFM_WIDTH(tc)  ((tc).width)
  231. #define TFM_FIX_WIDTH(tc)  ((tc).fix_width)
  232. #define TFM_HEIGHT(tc)  ((tc).height)
  233. #define TFM_FIX_HEIGHT(tc)  ((tc).fix_height)
  234. #define TFM_DEPTH(tc)  ((tc).depth)
  235. #define TFM_FIX_DEPTH(tc)  ((tc).fix_depth)
  236. #define TFM_ITALIC_CORRECTION(tc)  ((tc).italic_correction)
  237. #define TFM_FIX_ITALIC_CORRECTION(tc)  ((tc).fix_italic_correction)
  238.  
  239. /* The kern list.  */
  240. #define TFM_KERN(tc)  ((tc).kern)
  241.  
  242. /* The ligature list.  */
  243. #define TFM_LIGATURE(tc)  ((tc).ligature)
  244.  
  245.  
  246. /* This allocates and returns an array of `TFM_SIZE' elements, filled
  247.    with the information in the input file about each character.  */
  248. extern tfm_char_type *tfm_get_chars (void);
  249.  
  250. /* Return a pointer to the TFM information about the single character
  251.    CODE, or NULL if the character CODE wasn't in the TFM file.  */
  252. extern tfm_char_type *tfm_get_char (charcode_type code);
  253.  
  254. /* Return a single initialized `tfm_char_type' structure, and an
  255.    initialized array of `TFM_SIZE' elements, respectively.  These are
  256.    useful for output.  */
  257. extern tfm_char_type tfm_new_char (void);
  258. extern tfm_char_type *tfm_new_chars (void);
  259.  
  260. /* Take an array of `TFM_SIZE' elements and outputs them to
  261.    the PL file.  The fix_word dimensions aren't looked at.  */
  262. extern void tfm_put_chars (tfm_char_type *);
  263.  
  264. /* Output the single TFM character C.  */
  265. extern void tfm_put_char (tfm_char_type c);
  266.  
  267. /* When typesetting, the current character + `character' leads to
  268.    `ligature'.  The TFM format was extended in 1990 to allow for more
  269.    complicated ligatures than this, but we do not make those
  270.    distinctions.  */
  271. typedef struct
  272. {
  273.   charcode_type character;
  274.   charcode_type ligature;
  275. } tfm_ligature_type;
  276.  
  277. /* Similarly for kerns.  */
  278. typedef struct
  279. {
  280.   charcode_type character;
  281.   real kern;
  282. } tfm_kern_type;
  283.  
  284.  
  285. /* Return the kern between the characters LEFT and RIGHT; if no such
  286.    kern exists, return zero.  */
  287. extern real tfm_get_kern (tfm_char_type left, charcode_type right);
  288.  
  289. /* Make the kern for the character RIGHT in the list of `tfm_kern_type's
  290.    KERN_LIST be K (taken to be printer's points), replacing any kern
  291.    already present.  */
  292. extern void tfm_set_kern (list_type *kern_list, charcode_type right, real k);
  293.  
  294. /* Add a ligature in LIG_LIST for the character RIGHT to yield LIGATURE,
  295.    replacing any ligature already present.  */
  296. extern void tfm_set_ligature (list_type *lig_list, charcode_type right,
  297.                   charcode_type ligature);
  298.  
  299. #endif /* not TFM_FONT_LIBRARY_H */
  300.